<template>
  <div class="app-container">
    <form action="">
      姓名:<input type="text" v-model="student.name" /> 年龄:<input
        type="number"
        v-model="student.age"
      />
      <input type="button" value="搜索" @click="page()" />
    </form>
    <el-table :data="currentStudents" border style="width: 100%">
      <el-table-column prop="name" label="姓名"> </el-table-column>
      <el-table-column prop="gender" label="性别"> </el-table-column>
      <el-table-column prop="age" label="年龄"> </el-table-column>
      <el-table-column prop="addr" label="地址"> </el-table-column>
    </el-table>

    <div class="block">
    <span class="demonstration">完整功能</span>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pages"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
  </div>
</template>

<script>
import { pageList } from "@/api/user";
export default {
  data() {
    return {
      student: {
        name: "",
        age: "",
      },
      currentStudents: [],
      pages: -1,
      pageNum: 1,
      pageSize: 5,
      total:-1,
      updataStudent: {
        name: "",
        age: "",
        gender: "",
        addr: "",
      },
    };
  },
  methods: {
    page() {
      pageList(this.student, this.pageSize, this.pageNum).then((res) => {
        this.currentStudents = res.data;
        this.pages = res.pages;
        this.pageNum = res.pageNum;
        this.total = res.total;
      });
    },
    handleCurrentChange(pageNow){
        this.pageNum = pageNow;
        this.page();
    },
    handleSizeChange(size){
        this.pageSize = size;
        this.page();
    }
  },
  created() {
    this.page(); 
  },
};
</script>